package com.txm.drawPic;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TankWearGame extends JFrame {
    MyPanel myPanel = null;
    public static void main(String[] args) {
        new TankWearGame();
    }
    public TankWearGame(){
        myPanel = new MyPanel();
        Thread thread = new Thread(myPanel);
        thread.start();
        this.add(myPanel);
        this.addKeyListener(myPanel);
        this.setSize(Tank.PANEL_W + 318, Tank.PANEL_H + 40);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);

//      添加一个监听事件，当窗口关闭时记录关闭之前的游戏进度
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
//                super.windowClosing(e);
                myPanel.record.saveData();
            }
        });
    }
}
